﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Danser_Control.Managers;
using Danser_Entity.Entities;
using Danser_Entity.Queries.Filters;
using Danser_Entity.Queries.Data;

namespace Danser_AJAXEnabledWebApplication.DataSourceManagers
{
    /// <summary>
    /// Contains Data Source support methods for the Test Results and Test Params entities
    /// as a merged list
    /// </summary>
    public class TestResultsDataSourceManager
    {
        #region Memebers:

        /// <summary>
        /// Local list. holds a copy of the table's records in DB,
        /// + maybe 1 more empty record representing a new row in datagrid
        /// </summary>
        private IList<TestIntegratedData> _results;

        /// <summary>
        /// Control layer interface to access the DB
        /// </summary>
        private IQueryManager manager;

        #endregion

        #region C'tor:

        /// <summary>
        /// constructor
        /// </summary>
        public TestResultsDataSourceManager()
        {
            //instanciate control interface
            manager = ManagerFactory.QueryManager();
            //create empty string
            _results = new List<TestIntegratedData>(0);
        }

        #endregion

        #region Query Methods:

        /// <summary>
        /// SELECT method implementation
        /// </summary>
        /// <param name="filter">filter used in WHERE clause</param>
        /// <returns>data according to give SQL filter</returns>
        public IList<TestIntegratedData> GetTests(String filter)
        { 
            if (!String.IsNullOrEmpty(filter))
            {
                _results = manager.GetTestData(filter);
            }
            //else - return nothing (empty list)
            return _results;
        }

        #endregion
    }
}
